package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.Session;
import com.example.mapper.SessionMapper;
import com.example.service.SessionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 会话表 服务实现类
 * </p>
 *
 * @author chengtaoxie
 * @since 2023-10-23
 */
@Service
public class SessionServiceImpl extends ServiceImpl<SessionMapper, Session> implements SessionService {

    @Resource
    private SessionMapper sessionMapper;
    /**
     * 提问
     * @param contexts
     * @return
     */
    @Override
    public Result getSession(String contexts) {
        QueryWrapper<Session> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("contexts",contexts);
        Session selectOne = sessionMapper.selectOne(queryWrapper);
        if(selectOne == null){
            return Result.fail().message("抱歉！我无法回答你的问题！");
        }
        String answer = selectOne.getAnswer();
        return Result.ok(answer).message("回答成功");
    }
}
